namespace AltNetUK.Controllers
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Web;
    using System.Web.Mvc;
    using SimpleWebServices;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Models;
    using SimpleWebServices.Web.Mvc;
    using AltNetUK.Models;

    [InternalServerError]
    [Allow(Methods = "GET, HEAD, OPTIONS")]
    [CacheControl, ContentLanguage, ContentMD5]
    public sealed class EventController : Controller
    {
        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This needs to be an instance member.")]
        public ActionResult LanguageNegotiation(string date)
        {
            return new SeeOtherResult(date + ".en");
        }

        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This needs to be an instance member.")]
        public ActionResult ContentNegotiation(string date, CultureInfo language)
        {
            if (null == language)
            {
                throw new ArgumentNullException("language");
            }
            else if (CultureInfo.InvariantCulture == language)
            {
                throw new ArgumentOutOfRangeException("language");
            }

            string location = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.html", date, language.Name);
            return new SeeOtherResult(location);
        }

        public ActionResult CalendarRepresentation(string date)
        {
            Event model = Event.Calendar(date);
            this.Response.StatusCode = (int)model.Status;
            //this.Response.ContentType = "text/plain";

            return View(model);
        }

        public ActionResult HtmlRepresentation(string date, CultureInfo language)
        {
            if (null == language)
            {
                throw new ArgumentNullException("language");
            }
            else if (CultureInfo.InvariantCulture == language)
            {
                throw new ArgumentOutOfRangeException("language");
            }

            Event model = Event.Calendar(date);
            this.Response.StatusCode = (int)model.Status;

            return View(model);
        }
    }
}